#include "GameMsgPack.h"

CGameMsgPack::CGameMsgPack(void)
{
	Clear();
}

CGameMsgPack::~CGameMsgPack(void)
{
}

bool CGameMsgPack::SetData(UINT uiMsgID,const void* pkData,UINT uiDataSize,bool bFixedLen/* = true*/)
{
	if (pkData == NULL)
	{
		assert(0);
		return false;		
	}

	if (uiDataSize == 0)
	{
		assert(0);
		return false;		
	}

	if (uiDataSize >= MaxBufferLength)
	{
		assert(0);
		return false;	
	}

	m_uiMsgID = uiMsgID;
	m_uiDataLen = uiDataSize;
	memcpy_s(m_abyBuf,sizeof(m_abyBuf),pkData,uiDataSize);
	m_abyBuf[m_uiDataLen] = '\0';
	m_bFixedLenPack = bFixedLen;

	return true;
}

UINT CGameMsgPack::GetPackLength()
{
	return (sizeof(m_uiMsgID) + sizeof(m_uiDataLen) + sizeof(m_bFixedLenPack) + m_uiDataLen);
}

const BYTE* CGameMsgPack::GetData()
{
	return (const BYTE*)m_abyBuf;
}

UINT CGameMsgPack::GetMsgID()
{
	return m_uiMsgID;
}

UINT CGameMsgPack::GetMsgLength()
{
	return m_uiDataLen;
}

bool CGameMsgPack::IsFixedLenPack()
{
	return m_bFixedLenPack;
}

void CGameMsgPack::Clear()
{
	m_uiMsgID = -1;
	m_uiDataLen = 0;
	memset(m_abyBuf,0,sizeof(m_abyBuf));
	m_bFixedLenPack = true;
}